import model from 'models/model';
import { withLoading } from 'utils/dva';
import services from 'services';

export default model.extend({
  namespace: 'commonModel',
  state: {
    companyList: [],
    roleList: [],
    menuTree: [],
    userList: [],
    tempList: [],
    timeRangeGps: {}
  },

  subscriptions: {
    
  },
  effects: {
    // 获取公司列表
    * getCompanyList({ payload }, { call, update }) {
      const { data } = yield call(withLoading(services.company.getList), payload);
      yield update({ companyList: data.data });
    },
    // 获取角色列表
    * getRoleList({ payload }, { call, update }) {
      const { data } = yield call(withLoading(services.role.getList));
      yield update({ roleList: data });
    },
    // 获取用户列表
    * getUserList({ payload }, { call, update }) {
      const { data } = yield call(withLoading(services.user.getList), payload);
      yield update({ userList: data.data });
    },
    // 查询菜单数据
    * getDepartment({ payload }, { call, update }) {
      const { data } = yield call(withLoading(services.menu.allMenuTree), { ...payload });
      yield update({
        menuTree: data
      });
    },
    * getTemplateList({ payload }, { call, select, update }) {
      const { data }  = yield call(withLoading(services.chart.queryDataTemplates, 'list'), 
      { ps: 10, pn: 1, ...payload });
      yield update({ templateList: data.data });
    },
    * queryTimeRangeGps({ payload }, { call, update }) {
      const { data } = yield call(withLoading(services.equipment.queryTimeRangeGps), { ...payload });
      yield update({ timeRangeGps: data });
    }
    // 验证短息
    // * getRoleList({ payload }, { call, update }) {
    //   const { data } = yield call(withLoading(services.role.getList));
    //   yield update({ roleList: data });
    // }
  },
  reducers: {
    commonUpdateState(state, { payload }) {
      return {
        ...state,
        ...payload
      };
    }
  }
});
